package be.djdb.utils;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;


import be.djdb.Statics;

import be.djdb.generators.MYpanel;
import be.djdb.utils.table.OptionsTableModel;
/**
* @author Lieven Roegiers
* @copyright 2011
* @from JAVA_mylibs
* @version java 1.5+
*/
public class ProjectSettingsEditor extends JPanel{
	private static final long serialVersionUID = 709030836488571354L;
	private Projectsettings settings;
	private JTable table;
	/**
	 * 
	 * 		
	 * options =new ActionListener(){
			public void actionPerformed(ActionEvent evt) {
				settings.SaveSettings();//this that all settings from the prog are saved
		        final JFrame frame = new JFrame();
		        frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		        MYpanel pnltools = new MYpanel();
		        pnltools.addpanelitem("editorpanel","ok",new JButton(),new ActionListener(){
		        	public void actionPerformed (ActionEvent e){
		        		settings.SaveSettings();//this wil save all settings
		        		frame.dispose();
		        	}});
		        pnltools.addpanelitem("editorpanel","cancel",new JButton(),new ActionListener(){
		        	public void actionPerformed (ActionEvent e){
		        		settings.LoadSettings();//this wil reload all settings
		        		frame.dispose();
		        	}});
		        frame.add(pnltools.getpanel("editorpanel"), BorderLayout.SOUTH);
		        JPanel editor = settings.getEditor();
		        frame.add(editor,BorderLayout.NORTH);
		        frame.setVisible(true);
		        frame.pack();
			}
		};
	 */
    public ProjectSettingsEditor(Projectsettings settings){
    	this(settings,new Dimension(250,250));//constuctor
    }
    public ProjectSettingsEditor(Projectsettings settings,Dimension size){
    	super(new FlowLayout(FlowLayout.RIGHT));
    	//setLayout(new GridLayout(1,0));
    	this.settings = settings;
    	gui(size);
    }
	public void gui(Dimension size){
    	table = new JTable(new OptionsTableModel(settings));
        table.setAutoCreateRowSorter(true);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        table.setPreferredScrollableViewportSize(size);
        //table.set(true);
        add(new JScrollPane(table));
    }
    private  void log(Level level, String msg ){
        String tag ="<>>>>*"+Statics.LIBNAME+"-"+Statics.COPYRIGHTBY+"*<<<<>StreamManipulator";
        Logger.getLogger(ProjectSettingsEditor.class.getName()).log(level, tag + msg);
    }
}

